﻿$j.fn.extend({
    superButtonMouseoverEvent: function() {
        $('.leftCap', this).attr('class', 'leftCap leftCapover');
        $('.buttonIconCell', this).attr('class', 'buttonIconCell buttonIconCellover');
        $('.button ', this).attr('class', 'button buttonover');
        $('.labelCell ', this).attr('class', 'labelCell labelCellover');
        $('.rightCap', this).attr('class', 'rightCap rightCapover');
        $('.dropDownIconCell', this).attr('class', 'dropDownIconCell dropDownIconCellover');
        $('.comboArrow', this).attr('class', 'comboArrow comboArrowover');
        $('.dropDownLeftCap', this).attr('class', 'dropDownLeftCap dropDownLeftCapover');
    },
    superButtonMouseoutEvent: function() {
        $('.leftCap', this).attr('class', 'leftCap');
        $('.buttonIconCell', this).attr('class', 'buttonIconCell');
        $('.button ', this).attr('class', 'button');
        $('.labelCell ', this).attr('class', 'labelCell');
        $('.rightCap', this).attr('class', 'rightCap');
        $('.dropDownIconCell', this).attr('class', 'dropDownIconCell');
        $('.comboArrow', this).attr('class', 'comboArrow');
        $('.dropDownLeftCap', this).attr('class', 'dropDownLeftCap');
    },
    superButtonMousedownEvent: function(e) {
        var buttonId = $(this).attr('id');
        if ($('#' + buttonId).attr('axis') == 0) {
            $('.leftCap', this).attr('class', 'leftCap leftCapdown');
            $('.buttonIconCell', this).attr('class', 'buttonIconCell buttonIconCelldown');
            $('.button ', this).attr('class', 'button buttondown');
            $('.labelCell ', this).attr('class', 'labelCell labelCelldown');
            $('.rightCap', this).attr('class', 'rightCap rightCapdown');
            $('.dropDownIconCell', this).attr('class', 'dropDownIconCell dropDownIconCelldown');
            $('.comboArrow', this).attr('class', 'comboArrow comboArrowdown')
            $('.dropDownLeftCap', this).attr('class', 'dropDownLeftCap dropDownLeftCapdown');
        }
        else {
            var element = jQuery.event.element(e);
            if (element.id == buttonId + '_dropdown' || element.id == buttonId + '_rightCap' || element.id == buttonId + '_dropDownIconCell') {
                $('.rightCap', this).attr('class', 'rightCap rightCapdown');
                $('.dropDownIconCell', this).attr('class', 'dropDownIconCell dropDownIconCelldown');
                $('.comboArrow', this).attr('class', 'comboArrow comboArrowdown')
                $('.dropDownLeftCap', this).attr('class', 'dropDownLeftCap dropDownLeftCapdown');
            }
            else {
                $('.leftCap', this).attr('class', 'leftCap leftCapdown');
                $('.buttonIconCell', this).attr('class', 'buttonIconCell buttonIconCelldown');
                $('.button ', this).attr('class', 'button buttondown');
                $('.labelCell ', this).attr('class', 'labelCell labelCelldown');
            }
        }
    },
    superButtonMouseupEvent: function(e) {
        var buttonId = $(this).attr('id');
        if ($('#' + buttonId).attr('axis') == 0) {
            $('.leftCap', this).attr('class', 'leftCap leftCapover');
            $('.buttonIconCell', this).attr('class', 'buttonIconCell buttonIconCellover');
            $('.button ', this).attr('class', 'button buttonover');
            $('.labelCell ', this).attr('class', 'labelCell labelCellover');
            $('.rightCap', this).attr('class', 'rightCap rightCapover');
            $('.dropDownIconCell', this).attr('class', 'dropDownIconCell dropDownIconCellover');
            $('.comboArrow', this).attr('class', 'comboArrow comboArrowover');
            $('.dropDownLeftCap', this).attr('class', 'dropDownLeftCap dropDownLeftCapover');
        }
        else {
            var element = jQuery.event.element(e);
            if (element.id == buttonId + '_dropdown' || element.id == buttonId + '_rightCap' || element.id == buttonId + '_dropDownIconCell') {
                $('.rightCap', this).attr('class', 'rightCap rightCapover');
                $('.dropDownIconCell', this).attr('class', 'dropDownIconCell dropDownIconCellover');
                $('.comboArrow', this).attr('class', 'comboArrow comboArrowover');
                $('.dropDownLeftCap', this).attr('class', 'dropDownLeftCap dropDownLeftCapover');

            }
            else {
                $('.leftCap', this).attr('class', 'leftCap leftCapover');
                $('.buttonIconCell', this).attr('class', 'buttonIconCell buttonIconCellover');
                $('.button ', this).attr('class', 'button buttonover');
                $('.labelCell ', this).attr('class', 'labelCell labelCellover');
            }
        }
    },

    superButtonPopupControl: function(menuid, isUpdateControl) {
        var offset = $j(this).offset();
        var hei = $j(this).height();
        var pakid = menuid;
        if (isUpdateControl)
            pakid = '__' + pakid + '__';
        var ppakid = '#' + pakid;
        var id = $(this).attr('id');
        $j(ppakid).css({ left: offset.left, top: offset.top + hei, zIndex: 1000, position: 'absolute' });
        $j(ppakid).toggle();
        $j(ppakid).mouseup(function() {
            $(this).hide();
        });
        $j(document).mousedown(function(e) {
            var element = jQuery.event.element(e);
            if (!queryTheContainer(element, menuid, id))
                $j('#' + pakid).hide();
        });
        function queryTheContainer(e, pakid, buttonid) {
            while (e && e.tagName != 'BODY') {
                if (!e) return false;
                if (e.id == pakid || e.id == buttonid) {
                    return true;
                };
                e = e.parentNode;
            };
            return false;
        };
    },
    dropDownPopupControl: function(menuid, isUpdateControl, buttonid, e) {
        var pbuttonid = '#' + buttonid;
        var pObj = $j(pbuttonid);
        var offset = $j(pbuttonid).offset();
        var hei = $j(pbuttonid).height();
        var pakid = menuid;
        if (isUpdateControl)
            pakid = '__' + pakid + '__';
        var ppakid = '#' + pakid;
        $j(ppakid).css({ left: offset.left, top: offset.top + hei, zIndex: 2000, position: 'absolute' });
        $j(ppakid).toggle();
        $j.event.stop(e);
        $j(ppakid).children('a').mouseup(function() {
            $(ppakid).hide();
        });
        $j(document).mousedown(function(e) {
            var element = $j.event.element(e);
            if (!queryTheContainer(element, menuid, buttonid))
                $j(ppakid).hide();
        });
        function queryTheContainer(e, pakid, buttonid) {
            while (e && e.tagName != 'BODY') {
                if (!e) return false;
                if (e.id == pakid || e.id == buttonid) {
                    return true;
                };
                e = e.parentNode;
            };
            return false;
        };
    }
});

$j(function() {
    $j('.superButton').live('mousedown', function() {
        $j(this).superButtonMousedownEvent();
    });
    $j('.superButton').live('mouseup', function() {
        $j(this).superButtonMouseupEvent();
    });
    $j('.superButton').live('click', function() {
        $j('#__' + $j(this).attr('id') + '__').block({ message: null, fadeIn: 0, timeout: 500, overlayCSS: { backgroundColor: '#fff', cursor: 'default'} });
    });

    $j('.superTextButton').live('mouseover', function() {
        $j(this).superButtonMouseoverEvent();
    });
    $j('.superTextButton').live('mouseout', function() {
        $j(this).superButtonMouseoutEvent();
    });

    $j('.superTextButton').live('mousedown', function(e) {
        $j(this).superButtonMousedownEvent(e);
    });
    $j('.superTextButton').live('mouseup', function(e) {
        $j(this).superButtonMouseupEvent(e);
    });
    $j('.superTextButton').live('click', function() {
        $j('#__' + $j(this).attr('id') + '__').block({ message: null, fadeIn: 0, timeout: 500, overlayCSS: { backgroundColor: '#fff', cursor: 'default'} });
    });

});
function excelReport(reportId) {
    var theForm = document.forms['form1'];
    if (!theForm) {
        theForm = document.form1;
    }

    var _old_action = theForm.action;
    var _old_target = theForm.target;
    var _new_action; 
    if (_old_action.indexOf("?") == -1)
        _new_action = _old_action + "?_state=excelreport&reportid=" + reportId;
    else
        _new_action = _old_action + "&_state=excelreport&reportid=" + reportId;

    theForm.action = _new_action;
    theForm.target = "_blank";
    
    theForm.submit();

    theForm.action = _old_action;
    theForm.target = _old_target;
    return false;
    
}
